import requests
import execjs

with open('EcryptCode.js',mode= 'r',encoding='utf-8') as file:
    jsfile = file.read()
ctx = execjs.compile(jsfile)
traceid = ctx.call('Traceid')
kiv = ctx.call('bbbb')
e = '{"query":"方正证券","pageNum":1,"limit":15}'
b = ctx.call('getData',e,kiv)

cookies = {
    'wd_guid': 'a1166b56-7495-43a7-9d9c-6f84123df0d5',
    'historyState': 'state',
    'R_S_IDS': '//www.baidu.com/',
    '__c': '1726380764',
    '__g': '-',
    '__l': 'l=%2Fwww.kanzhun.com%2F&r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DT9fitppj_KhgXFE6a78Eyg3vjlFAfWgLdHZq6uwFzKINIHyl7znUREZQHpzDUdmv%26wd%3D%26eqid%3Dea8a9574005bd2fc0000000666e67ad9',
    'Hm_lvt_1f6f005d03f3c4d854faec87a0bee48e': '1725522701,1725529513,1726378973,1726380764',
    'HMACCOUNT': 'A263C5ACD667F419',
    'Hm_lpvt_1f6f005d03f3c4d854faec87a0bee48e': '1726380768',
    'wbrwsid': '45759753',
    '__a': '60133177.1725320890.1726378973.1726380764.21.5.3.21',
}

headers = {
    'authority': 'www.kanzhun.com',
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
    # 'cookie': 'wd_guid=a1166b56-7495-43a7-9d9c-6f84123df0d5; historyState=state; R_S_IDS=//www.baidu.com/; __c=1726380764; __g=-; __l=l=%2Fwww.kanzhun.com%2F&r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DT9fitppj_KhgXFE6a78Eyg3vjlFAfWgLdHZq6uwFzKINIHyl7znUREZQHpzDUdmv%26wd%3D%26eqid%3Dea8a9574005bd2fc0000000666e67ad9; Hm_lvt_1f6f005d03f3c4d854faec87a0bee48e=1725522701,1725529513,1726378973,1726380764; HMACCOUNT=A263C5ACD667F419; Hm_lpvt_1f6f005d03f3c4d854faec87a0bee48e=1726380768; wbrwsid=45759753; __a=60133177.1725320890.1726378973.1726380764.21.5.3.21',
    'href': 'https://www.kanzhun.com/search?pageNum=1&query=%E6%96%B9%E6%AD%A3%E8%AF%81%E5%88%B8&type=5',
    'referer': 'https://www.kanzhun.com/search?pageNum=1&query=%E6%96%B9%E6%AD%A3%E8%AF%81%E5%88%B8&type=5',
    'reqsource': 'fe',
    'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'traceid': traceid,
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0',
    'x-requested-with': 'XMLHttpRequest',
}

params = {
    'b': b,
    'kiv': kiv,
}

with open('DecyptCode.js',mode='r',encoding='utf-8') as file:
    DecyptFile = file.read()
decypt = execjs.compile(DecyptFile)


response = requests.get(
    'https://www.kanzhun.com/api_to/search/job.json',
    params=params,
    cookies=cookies,
    headers=headers
)
web_data = response.text
# print(web_data)
# print(response)
DecyptData = decypt.call('DectyptData',web_data,kiv)
print(DecyptData)